import type { FormSchema } from '@/components/core/schema-form/';
import { InboxOutlined } from '@ant-design/icons-vue';
import { downloadAttament } from '@/api/workorder/common/attachment';
import { reactive } from 'vue';

// 当前页面使用的数据
export let uploadFileReturnVisitObject = reactive({
  uploadFileList: [],
  defaultFileList: []
});

export const returnVisitschemas: FormSchema[] = [
  {
    field: 'returnVisitNo',
    component: 'Input',
    label: '回访单号',
    colProps: {
      span: 12,
    },
    componentProps: {
      disabled: true
    },
  },
  {
    field: 'returnTime',
    component: 'DatePicker',
    label: '回访时间',
    
    colProps: {
      span: 12,
    },
    componentProps: {
      showTime: true,
      style: {
        width: '100%',
      },
    },
    rules: [{ required: true, type: 'string' }]
  },
  {
    field: 'returnVisitors',
    component: 'Input',
    label: '回访人',
    colProps: {
      span: 12,
    },
    rules: [{ required: true, type: 'string' }, { max: 40, message: '回访人不能大于20个字' }]
  },
  {
    field: 'returnObject',
    component: 'Input',
    label: '回访对象',
    colProps: {
      span: 12,
    },
    rules: [{ required: true, type: 'string' }, { max: 40, message: '回访对象不能大于20个字' }]
  },
  {
    field: 'returnCall',
    component: 'Input',
    label: '回访电话',
    colProps: {
      span: 12,
    },
    rules: [{ required: true, type: 'string' },  {
      required: false,
      type: 'string',
      validator: (_, value) => {
        let regPhone = /^[1][3,4,5,7,8][0-9]{9}$/;
        let regTel = /^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$/;
        const isError = !(regPhone.test(value) || regTel.test(value));
        if (value && isError) {
          return Promise.reject('请输入正确的手机号码或固话号码');
        } else {
          return Promise.resolve();
        }
      },
    }, { max: 13, message: '回访电话不能大于13个字符' }]
  },
  {
    field: 'citizenCall',
    component: 'Input',
    label: '市民电话',
    colProps: {
      span: 12,
    },
    rules: [{ required: true, type: 'string' },  {
      required: false,
      type: 'string',
      validator: (_, value) => {
        let regPhone = /^[1][3,4,5,7,8][0-9]{9}$/;
        let regTel = /^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$/;
        const isError = !(regPhone.test(value) || regTel.test(value));
        if (value && isError) {
          return Promise.reject('请输入正确的手机号码或固话号码');
        } else {
          return Promise.resolve();
        }
      },
    }, { max: 13, message: '市民电话不能大于13个字符' }]
  },
  {
    field: 'returnMethod',
    component: 'RadioGroup',
    label: '回访方式',
    colProps: {
      span: 12,
    },
    defaultValue: '电话回访',
    componentProps: {
      options: [
        {
          label: '电话回访',
          value: '电话回访',
        },
        {
          label: '上门回访',
          value: '上门回访',
        },
      ],
    },
  },
  {
    field: 'processOpinion',
    component: 'RadioGroup',
    label: '服务过程',
    colProps: {
      span: 24,
    },
    defaultValue: '0',
    componentProps: {
      options: [
        {
          label: '满意',
          value: '0',
        },
        {
          label: '基本满意',
          value: '1',
        },
        {
          label: '不满意',
          value: '2',
        },
        {
          label: '当事人联系不上',
          value: '3',
        },
      ],
    },
  },
  {
    field: 'resultOpinion',
    component: 'RadioGroup',
    label: '办理结果',
    colProps: {
      span: 24,
    },
    defaultValue: '0',
    componentProps: {
      options: [
        {
          label: '满意',
          value: '0',
        },
        {
          label: '基本满意',
          value: '1',
        },
        {
          label: '不满意',
          value: '2',
        },
        {
          label: '当事人联系不上',
          value: '3',
        },
      ],
    },
  },
  {
    field: 'describe',
    component: 'InputTextArea',
    label: '过程描述',
    colProps: {
      span: 24,
    },
    componentProps: {
      rows: 6
    },
    rules: [{ required: false, type: 'string' }, { max: 10000, message: '过程描述不能大于5000个字' }]
  },
  {
    field: 'filledTime',
    component: 'DatePicker',
    label: '登记时间',
    colProps: {
      span: 12,
    },
    componentProps: {
      showTime: true,
      style: {
        width: '100%',
      },
      disabled: true
    },
  },
  {
    field: 'filledBy',
    component: 'Input',
    label: '登记人',
    colProps: {
      span: 12,
    },
    componentProps: {
      disabled: true
    },
  },
  {
    field: 'attament',
    component: 'UploadDragger',
    label: '附件',
    colProps: {
      span: 24,
    },
    vShow: false,
    componentProps: {
      hidden: true,
      beforeUpload: (() => {
        return false;
      }),
      onChange: ((fileList: any) => {
        uploadFileReturnVisitObject.uploadFileList = fileList.fileList
      }),
      showUploadList: {
        showDownloadIcon: true
      },
      onDownload: ((file) => {
        // 文件下载
        downloadAttament(file.uid)
      })
    },
    componentSlots: {
      default: () => (
        <div>
          <p><InboxOutlined /></p>
          <p style={'color:blue'}>将文件拖到此处或点击上传</p>
        </div>
      ),
    },
  },
];



